Algebraic Data Types for Object-oriented Datalog
نویسندگان
چکیده
Value lookup(Context ctxt, Parameter p) { exists(Function f, int i | appliesTo(ctxt, f) and p = f.getParameter(i) and result = get(ctxt, i)) } With these preparations out of the way, we now show three representative clauses of the eval predicate: analysis of numeric literals as an example of a simple base case (where we use appliesTo to restrict the range of the otherwise unused parameter ctxt), and the two crucial cases of parameter and return value passing. To analyse a use of a parameter p we look it up in the context; to analyse a function call, we construct the appropriate calling context, and use the auxiliary predicate retval to determine the possible return values of the callee in that context. That predicate, in turn, considers the return statements in the function to determine possible return values: AbstractValue eval(Context ctxt, Expr e) { e instanceof NumberLiteral and appliesTo(ctxt, e.getEnclosingFunction()) and result = Number() or exists(SimpleParameter p | e = p.getVariable().getAnAccess() and result = ctxt.lookup(p)) or exists(Function f | calls(ctxt, e, f) and result = retval(evalArgs(ctxt, e, f, 0), f)) or ... } AbstractValue retval(Context ctxt, Function f) { exists(ReturnStmt ret | ret = f.getAReturnStmt() and result = eval(ctxt, ret.getExpr())) }Value retval(Context ctxt, Function f) { exists(ReturnStmt ret | ret = f.getAReturnStmt() and result = eval(ctxt, ret.getExpr())) } Extending these predicates to model all of ECMAScript 2016 is a non-trivial task, but takes no more than about 500 lines of QL. We want to emphasise, however, that we do not mean to claim that CPA is a silver bullet for the analysis of JavaScript, the challenges of which are manifold and extensively documented in the literature (Jensen et al. 2009; Kashyap et al. 2014; Park and Ryu 2015; Schäfer et al. 2013; Sridharan et al. 2012), we simply use it as an example of a non-trivial context sensitivity policy that nicely demonstrates the use of recursive algebraic data types: since contexts can be lists of arbitrary length, it is not clear how they could be represented in plain QL. 6.2 Constructing control flow graphs As our next example, we show how to construct intra-procedural control ow graphs for programs written in a very small subset of Java, comprising just four kinds of statements: expression statements, throw, try with catch (but no finally) and block statements. We ignore any control ow resulting from expression evaluation. The CFG contains one node for each statement, plus one entry node and one exit node for each callable (that is, method or constructor): newtype CfgNode = StmtNode(Stmt s) or EntryNode(Callable c) or ExitNode(Callable c) CFG edges are labelled with completions that indicate the reason for the ow. We have two kinds of completions: the normal completion indicating normal termination of a statement; and throw completions, indicating that a statement has thrown an exception: , Vol. 1, No. 1, Article 1. Publication date: April 2017.
منابع مشابه
Inheritance in Object Oriented Datalog : A Modular Logic Programming
Modularity is a special form of logic programming composition that allows incremental development and code reusability. It is natural to be considered as the formal framework to supply semantics to languages of logic programs (such as datalog) when the underlying data model is object oriented. We show here that a) for various interesting forms of inheritance, clean and natural semantics can ind...
متن کاملQL: Object-oriented Queries on Relational Data
This paper describes QL, a language for querying complex, potentially recursive data structures. QL compiles to Datalog and runs on a standard relational database, yet it provides familiar-looking object-oriented features such as classes and methods, reinterpreted in logical terms: classes are logical properties describing sets of values, subclassing is implication, and virtual calls are dispat...
متن کاملType Derivation Using the Projection Operation
We present techniques for deriving types from existing object-oriented types using the rela-tional algebraic projection operation and for inferring the methods that are applicable to these types. Such type derivation occurs, for example, as a result of deening algebraic views over object types. We refactor the type hierarchy and place the derived types in the type hierarchy in such a way that t...
متن کاملDifunctorial Semantics of Object Calculus
In this paper we give a denotational model for Abadi and Cardelli’s first order object calculus FOb1+×μ (without subtyping) in the category pCpo. The key novelty of our model is its extensive use of recursively defined types, supporting self-application, to model objects. At a technical level, this entails using some sophisticated techniques such as Freyd’s algebraic compactness to guarantee th...
متن کاملSliced bananas on opaque data
Algebraic data types and catamorphisms (folds) play a central role in functional programming as they allow programmers to define recursive data structures and operations on them uniformly by structural recursion. Likewise, in object-oriented (OO) programming, recursive hierarchies of object types with virtual methods play a central role for the same reason. There is a semantical correspondence ...
متن کاملROCK & ROLL: A Deductive Object-Oriented Database with Active and Spatial Extensions
ROCK & ROLL is a deductive object-oriented database system that supports two languages, one imperative and the other deductive, both derived from the same object-oriented data model. As the languages share a common type system, they can be integrated without manifesting impedance mismatches, and thus programmers can conveniently exploit both deductive and imperative features in a single applica...
متن کاملذخیره در منابع من
با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید
عنوان ژورنال:
دوره شماره
صفحات -
تاریخ انتشار 2017